"""
Tensor的索引与数据筛选

- torch.where(condition, x, y) 按照条件从x和y中选出满足条件的元素组成心的tensor
- torch.gather(input, dim, index, out=None) 在指定维度上按照索引赋值输出tensor
- torch.index_select(input, dim, index, out=None) 按照指定索引输出为tensor
- torch.masked_select(input, mask, out=None) 按照mask输出tensor 输出为向量
- torch.take(input, indices) 将输入看成1D-tensor 按照索引得到输出的tensor
- torch.nonzero(input, out=None) 输出非0元素的坐标

"""
import torch

# a = torch.rand(4, 4)
# b = torch.rand(4, 4)
# print(a)
# print(b)
# out = torch.where(a > 0.5, a, b)
# print(out)

# a = torch.rand(4, 4)
# print(a)
# out = torch.index_select(a, dim=0, index=torch.tensor([0, 3, 2]))
# print(out)

# a = torch.linspace(1, 18, 16).view(4, 4)
# print(a)
# out = torch.gather(a, dim=0, index=torch.tensor([[0, 1, 1, 1],
#                                                  [0, 1, 2, 2],
#                                                  [0, 1, 3, 3]]))
# print(out)

# a = torch.linspace(1, 16, 16).view(4, 4)
# print(a)
# out = torch.take(a, index=torch.tensor([0, 15, 13, 10]))
# print(out)

# a = torch.tensor([[0, 1, 2, 0], [2, 3, 0, 1]])
# print(a)
# out = torch.nonzero(a)
# print(out)


